import { createRequire } from 'node:module'
import antfu from '@antfu/eslint-config'

const autoImportGlobals = createRequire(import.meta.url)('./.eslintrc-auto-import.json')

export default antfu({
  vue: {
    overrides: {
      'vue/block-order': ['error', {
        order: ['template', 'script', 'style'],
      }],
      'vue/html-closing-bracket-newline': [
        'warn',
        {
          multiline: 'never',
        },
      ],
      // 使用组件使用 PascalCase 形式
      'vue/component-name-in-template-casing': [
        'warn',
        'PascalCase',
        {
          registeredComponentsOnly: false,
        },
      ],
      'vue/max-attributes-per-line': ['error', {
        singleline: {
          max: 1,
        },
        multiline: {
          max: 1,
        },
      }],
    },
  },
  formatters: {
    /**
     * Format CSS, LESS, SCSS files, also the `<style>` blocks in Vue
     * By default uses Prettier
     */
    css: true,
    /**
     * Format HTML files
     * By default uses Prettier
     */
    html: true,

    // Prettier options
    prettierOptions: {
      printWidth: 100,
      tabWidth: 2,
      singleQuote: true,
      semi: false,
      trailingComma: 'all',
      bracketSameLine: true,
      bracketSpacing: true,
      singleAttributePerLine: true,
      proseWrap: 'never',
      endOfLine: 'auto',
      htmlWhitespaceSensitivity: 'strict',
      vueIndentScriptAndStyle: true,
    },
  },
  rules: {
    'no-with': 'off',
    'no-console': ['error', {
      allow: ['warn', 'error', 'log'],
    }],
    'import/extensions': ['warn', 'ignorePackages'],
    'style/brace-style': ['warn', '1tbs'],
    'regexp/no-unused-capturing-group': ['error', {
      fixable: true,
      allowNamed: true,
    }],
    'jsdoc/require-returns-description': 'off',
    'jsdoc/check-param-names': 'off',
    'style/max-len': ['warn', {
      code: 100, // 行最大长度
      tabWidth: 2, // 制表符宽度
      ignoreUrls: true, // 忽略 URL
      ignoreStrings: true, // 忽略字符串
      ignoreTemplateLiterals: true, // 忽略模板字符串
      ignoreComments: true, // 忽略注释
    }],
  },
  // settings: {
  //   // 添加别名解析器
  //   'import/resolver': {
  //     // 别名解析器插件 https://github.com/import-js/eslint-plugin-import/wiki/Resolvers
  //     'eslint-import-resolver-custom-alias': {
  //       alias: {
  //         '@': './src',
  //       },
  //       extensions: ['.js', '.vue', '.css', '.scss', '.json', '.png', '.svg', '.gif'],
  //     },
  //   },
  // },
  languageOptions: {
    parserOptions: {
      ecmaVersion: 'latest', // 或者明确指定版本如 2024
    },
    globals: autoImportGlobals.globals,
  },
  ignores: [
    'node_modules',
    'dist',
    'package-lock.json',
    'package.json',
    'docs',
    'dist.*',
    // 'wflow-pro',
  ],
})
